package lottery.com.lotteryticket.comm

import java.util.ArrayList
import java.util.Random

/**
 * 计算类
 */

class LotteryTicket {

    var ticket: ArrayList<String>? = null

    constructor() {
        ticket = tickets()
    }

    //单注
    private fun tickets(): ArrayList<String> {
        var ticketsString = ArrayList<String>()
        ticketsString.addAll(header())
        ticketsString.add(footer())
        return ticketsString
    }

    //红球
    private fun header(): ArrayList<String> {
        var ticketsString = ArrayList<String>()
        var ticketsInteger = ArrayList<Int>()

        var num = 0
        var random = Random()
        while (num < 6) {
            var randomValue = random.nextInt(32) + 1
            if (!ticketsInteger.any { it == randomValue }) {
                ticketsInteger.add(randomValue)
                if (randomValue < 0) {
                    ticketsString.add("0$randomValue")
                } else {
                    ticketsString.add("$randomValue")
                }
                num++
            }
        }
        return ticketsString
    }

    //蓝球
    private fun footer(): String {
        var random = Random()
        var randomValue = random.nextInt(15) + 1
        return if (randomValue < 0) {
            "0$randomValue"
        } else {
            "$randomValue"
        }
    }
}
